<?php

if(!defined('OT_ROOT')) {
	exit('Access Denied');
}



class AdmTpl{

	// 登录页面
	public static function LoginWeb(){
		global $sysAdminArr;

		switch ($sysAdminArr['SA_tplDir']){
			case 'youyou/':
				return AdmTplYouyou::LoginWeb();
				break;
		
			default :
				return AdmTplDef::LoginWeb();
				break;
		}
	}

	// 首页页面
	public static function IndexWeb(){
		global $sysAdminArr;

		switch ($sysAdminArr['SA_tplDir']){
			case 'youyou/':
				return AdmTplYouyou::IndexWeb();
				break;
		
			default :
				return AdmTplDef::IndexWeb();
				break;
		}
	}


	// 通用配置文件
	public static function WebConfig(){
		global $sysAdminArr;

		switch ($sysAdminArr['SA_tplDir']){
			case 'youyou/':
				return AdmTplYouyou::WebConfig();
				break;
		
			default :
				return AdmTplDef::WebConfig();
				break;
		}
	}

	// 表格页头
	public static function TableTop($img, $IDname, $CNname){
		global $sysAdminArr;

		switch ($sysAdminArr['SA_tplDir']){
			case 'youyou/':
				return AdmTplYouyou::TableTop($img, $IDname, $CNname);
				break;
		
			default :
				return AdmTplDef::TableTop($img, $IDname, $CNname);
				break;
		}
	}

	// 表格页头2
	public static function TableTop2($img, $IDname, $CNname){
		global $sysAdminArr;

		switch ($sysAdminArr['SA_tplDir']){
			case 'youyou/':
				return AdmTplYouyou::TableTop2($img, $IDname, $CNname);
				break;
		
			default :
				return AdmTplDef::TableTop2($img, $IDname, $CNname);
				break;
		}
	}

	// 主菜单
	public static function MenuStr($CNname, $ENname, $styleStr='', $judGet=true){
		global $sysAdminArr;

		switch ($sysAdminArr['SA_tplDir']){
			case 'youyou/':
				return AdmTplYouyou::MenuStr($CNname, $ENname, $styleStr, $judGet);
				break;
		
			default :
				return AdmTplDef::MenuStr($CNname, $ENname, $styleStr, $judGet);
				break;
		}
	}

	// 子菜单
	public static function MenuStr2($menuSelID, $menuID, $menuName, $URL, $styleStr=''){
		global $sysAdminArr;

		switch ($sysAdminArr['SA_tplDir']){
			case 'youyou/':
				return AdmTplYouyou::MenuStr2($menuSelID, $menuID, $menuName, $URL, $styleStr);
				break;
		
			default :
				return AdmTplDef::MenuStr2($menuSelID, $menuID, $menuName, $URL, $styleStr);
				break;
		}
	}

	// 登陆页验证码
	public static function ShowVerCode($svcForm,$svcId=''){
		global $sysAdminArr;

		switch ($sysAdminArr['SA_tplDir']){
			case 'youyou/':
				return AdmTplYouyou::ShowVerCode($svcForm,$svcId);
				break;
		
			default :
				return AdmTplDef::ShowVerCode($svcForm,$svcId);
				break;
		}
	}

	// 左侧子菜单列表
	public static function LeftMenu(){
		global $DB,$MB,$autoOpenStr;

		$autoOpenStr='';
		$menuSelID	= 'revSelf';
		$retStr = '
		<div id="leftMenuID'. $menuSelID .'" style="display:none;">
		';
			$menuArr = self::DiyMenuArr('revSelf');
			foreach ($menuArr as $val){
				$retStr .= self::MenuStr2($menuSelID, $val['id'], $val['name'], $val['url']);
			}

		$autoOpenStr='';
		$menuSelID	= 'user';
		$retStr .= '
		</div>
		<div id="leftMenuID'. $menuSelID .'" style="display:none;">
		';
			$menuArr = self::DiyMenuArr('user');
			foreach ($menuArr as $val){
				$retStr .= self::MenuStr2($menuSelID, $val['id'], $val['name'], $val['url']);
			}

		$autoOpenStr='';
		$menuSelID	= 'database';
		$retStr .= '
		</div>
		<div id="leftMenuID'. $menuSelID .'" style="display:none;">
		';
			$menuArr = self::DiyMenuArr('database');
			foreach ($menuArr as $val){
				$retStr .= self::MenuStr2($menuSelID, $val['id'], $val['name'], $val['url']);
			}

		$menuSelID=0;
		$payArr = AdmArea::GetAppIdArr();	// 获取已购买插件appID数组
		$menuexe=$DB->query('select MT_ID,MT_theme,MT_themeStyle,MT_URL,MT_menuID from '. OT_dbPref .'menuTree where MT_level=1 and MT_userState=1 and MT_state=1 and MT_appID in ('. implode(',',$payArr) .') and MT_ID not in (0'. AdmTpl::NoIdMenuArr('menu') .') order by MT_menuID ASC,MT_rank ASC');
			while ($row = $menuexe->fetch()){
				if ($menuSelID != $row['MT_menuID']){
					$menuSelID = $row['MT_menuID'];
					
					$autoOpenStr='';
					$retStr .= '</div><div id="leftMenuID'. $menuSelID .'" style="display:none;">';
				}
				$retStr .= self::MenuStr2($menuSelID,$row['MT_ID'],$row['MT_theme'],$row['MT_URL'],$row['MT_themeStyle']);
			}
		unset($menuexe);

		$retStr .= '
		</div>
		';

		return $retStr;
	}

	// 图片加载
	public static function ImgSrc($imgName){
		global $sysAdminArr;

		switch ($sysAdminArr['SA_tplDir']){
			case 'youyou/':
				return 'template/youyou/images/'. $imgName .'.gif';
				break;
		
			default :
				return 'template/default/images/'. $imgName .'.gif';
				break;
		}
	}

	// 自定义菜单数组
	public static function DiyMenuArr($type){
		$retArr = array();
		switch ($type){
			case 'revSelf':	// 修改密码
				$retArr[] = array('id'=>'修改用户名或密码', 'name'=>'修改用户名或密码', 'url'=>'admin.php?mudi=revPwd');
				$retArr[] = array('id'=>'其他信息设置',		'name'=>'其他信息设置',		'url'=>'admin.php?mudi=revOthers');
				break;
		
			case 'user':	// 用户管理
				if (AppBase::Jud()){
					$retArr[] = array('id'=>'用户组管理',		'name'=>'用户组管理',		'url'=>'memberGroup.php?mudi=manage');
					$retArr[] = array('id'=>'用户组权限设置',	'name'=>'用户组权限设置',	'url'=>'memberGroup.php?mudi=setRight');
				}
				$retArr[] = array('id'=>'用户管理',		'name'=>'用户管理',		'url'=>'member.php?mudi=manage');
				break;
		
			case 'database':
				if (AreaApp::Jud(161)){
					$retArr[] = array('id'=>999920, 'name'=>'多网站登录', 'url'=>'siteLogin.php?mudi=manage');
				}
				if (OT_Database=='sqlite'){
					$retArr[] = array('id'=>999901, 'name'=>'数据库备份/压缩', 'url'=>'dbBak.php?mudi=manage');
				}elseif (OT_Database=='mysql'){
					$retArr[] = array('id'=>999902, 'name'=>'数据库备份', 'url'=>'dbBakMySQL.php?mudi=backup');
					$retArr[] = array('id'=>999903, 'name'=>'数据库恢复', 'url'=>'dbBakMySQL.php?mudi=restore');
				}
				$retArr[] = array('id'=>999905, 'name'=>'程序文件备份',		'url'=>'softBak.php?mudi=backup');
				$retArr[] = array('id'=>999906, 'name'=>'程序/数据库备份',	'url'=>'softBak.php?mudi=manage');
				$retArr[] = array('id'=>999907, 'name'=>'后台参数配置',		'url'=>'sysAdmin.php?mudi=manage');
				$retArr[] = array('id'=>999908, 'name'=>'程序文件检查',		'url'=>'sysCheckFile.php?mudi=manage');
				$retArr[] = array('id'=>999909, 'name'=>'数据处理管理',		'url'=>'dataDeal.php?mudi=manage&dataType=news&dataTypeCN='. urlencode('数据处理'));
				$retArr[] = array('id'=>999910, 'name'=>'后台菜单排序',		'url'=>'adminMenu.php?mudi=manage');
				$retArr[] = array('id'=>999911, 'name'=>'自定义静态页',		'url'=>'makeDiy.php?mudi=manage&dataTypeCN='. urlencode('自定义静态页') .'');
				$retArr[] = array('id'=>999912, 'name'=>'上传文件管理',		'url'=>'serverFile.php?mudi=manage');
				$retArr[] = array('id'=>999913, 'name'=>'后台操作日志',		'url'=>'memberLog.php?mudi=manage');
				$retArr[] = array('id'=>999914, 'name'=>'后台在线记录',		'url'=>'memberOnline.php?mudi=manage');
				$retArr[] = array('id'=>999915, 'name'=>'在线升级记录',		'url'=>'update.php?mudi=manage');
				$retArr[] = array('id'=>999916, 'name'=>'数据库错误日志',	'url'=>'dbErr.php?mudi=manage');
				$retArr[] = array('id'=>999917, 'name'=>'特定文档查看',		'url'=>'editFile.php?mudi=manage');
				// $retArr[] = array('id'=>999919, 'name'=>'API调用日志',		'url'=>'apiRecord.php?mudi=manage');
				break;
		}
		
		return $retArr;
	}

	// 不加载菜单ID数组
	public static function NoIdMenuArr($type=''){
		global $sysAdminArr;

		$navNoIdStr = $menuNoIdStr = '';
		if (strpos(''. $sysAdminArr['SA_funcCloseArea'], '|info|') !== false){
			$navNoIdStr .= ',345,454';	// 345文章管理 454模板管理
			$menuNoIdStr .= ',354,346,397,995,387,13,383,382';	// 354,346栏目 397单篇页 995顶部菜单 387底部栏目 13友链 383广告管理 382生成sitemap
		}
		if (strpos(''. $sysAdminArr['SA_funcCloseArea'], '|users|') !== false){
			$navNoIdStr .= ',429';	// 429会员管理
			$menuNoIdStr .= '';
		}
		if ($type == 'nav'){
			return $navNoIdStr;
		}elseif ($type == 'menu'){
			return $menuNoIdStr;
		}else{
			return array('nav' => $navNoIdStr, 'menu' => $menuNoIdStr);
		}
	}

}